package com.edfu.core.coursemgt.persistence.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import com.edfu.core.identitymgt.persistence.entity.UserEntity;

@Entity
@Table(name="lesson", uniqueConstraints=@UniqueConstraint(columnNames={"name" , "courseoffering_id"}))
public class LessonEntity implements ICourseMgtEntity {
	
	private long id;
	private String title;
	private String name;
	private String description;
	private String contentDirectory;
	private UserEntity author;
	private String language;
	private float price;
	private boolean published;
	private int lessonNo;
	private CourseOfferingEntity courseOffering;
	private List<LessonUnitEntity> units;
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getTitle() {
		return title;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public String getContentDirectory() {
		return contentDirectory;
	}
	public void setContentDirectory(String contentDirectory) {
		this.contentDirectory = contentDirectory;
	}
	@ManyToOne
	@JoinColumn(name = "author_id", nullable = false)
	public UserEntity getAuthor() {
		return author;
	}
	public void setAuthor(UserEntity author) {
		this.author = author;
	}
	public String getLanguage() {
		return language;
	}
	public void setLanguage(String language) {
		this.language = language;
	}
	public float getPrice() {
		return price;
	}
	public void setPrice(float price) {
		this.price = price;
	}
	public boolean isPublished() {
		return published;
	}
	public void setPublished(boolean published) {
		this.published = published;
	}
	
	public int getLessonNo() {
		return lessonNo;
	}
	public void setLessonNo(int lessonNo) {
		this.lessonNo = lessonNo;
	}
	@ManyToOne
	@JoinColumn(name = "courseoffering_id", nullable = true)
	public CourseOfferingEntity getCourseOffering() {
		return courseOffering;
	}
	public void setCourseOffering(CourseOfferingEntity courseOffering) {
		this.courseOffering = courseOffering;
	}
	
	@OneToMany(mappedBy = "lesson", fetch= FetchType.EAGER, cascade=CascadeType.ALL)
	public List<LessonUnitEntity> getUnits() {
		return units;
	}
	public void setUnits(List<LessonUnitEntity> units) {
		this.units = units;
	}
	
}
